<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100之间的整数">
<button onclick="f()">猜一猜</button>
<h1>结果：<span></span></h1>
<script>
    let x = parseInt(Math.random()*100)+1;
    let guess = document.querySelector("input");
    let s = document.querySelector("span");
    let count = 0;
    function f() {
        count++;
        if(isNaN(guess.value)){
            s.innerText = "请输入数字";
            return;
        }
        /*进行比较的时候会自动转化为数值*/
        if(guess.value>x){
            s.innerText = "猜大了";
            return;
        }
        if(guess.value<x){
            s.innerText = "猜小了";
            return;
        }
        s.innerText = "恭喜你！猜对了！！！一共猜了"+count+"次";
    }
</script>
</body>
</html>